#!/bin/bash
source /etc/profile
. $BEETLE_SHELL_PATH/error.sh

# 分支名
branch=$1

codePath=/usr/local/beetle/code/beetle-api
workPath=/usr/local/winit_tomcat/webapps
projectName=beetle
configPath=/usr/local/beetle/config/beetle-api
bakPath=/usr/beetle/appbak/beetle-api
bakName=beetle-api
serverPath=/usr/local/winit_tomcat

bash $BEETLE_SHELL_PATH/git_checkout.sh ${codePath} ${branch} || error_exit

bash $BEETLE_SHELL_PATH/bak.sh ${workPath} ${projectName} ${bakPath} ${bakName} || error_exit

cd ${codePath} || error_exit
mvn clean package|| error_exit
rm -rf ${workPath}/${projectName}/* || error_exit
cp target/beetle.war ${workPath}/${projectName}/ || error_exit
cd ${workPath}/${projectName} || error_exit
unzip beetle.war || error_exit
rm -rf beetle.war || error_exit
# rm -rf ${workPath}/${projectName}/WEB-INF/classes/config.properties || error_exit
# rm -rf ${workPath}/${projectName}/WEB-INF/classes/logback.xml || error_exit
cp ${configPath}/config.properties ${workPath}/${projectName}/WEB-INF/classes/config.properties || error_exit
cp ${configPath}/logback.xml ${workPath}/${projectName}/WEB-INF/classes/logback.xml || error_exit
cd ${serverPath} || error_exit
bash tomcat.sh restart centos /usr/local/java/jdk1.7.0_79 /usr/local/winit_tomcat 8081 || error_exit
tail -fn100 logs/catalina.out
